package com.hk.admin.module.system.service;

import com.hk.admin.common.base.service.BaseService;
import com.hk.admin.common.util.FileUtil;
import com.hk.admin.spring.config.FileUploadConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
public class FileService extends BaseService {

    @Autowired
    private FileUploadConfig fileUploadConfig;

    /**
     * 上传图片
     *
     * @param file
     * @return
     */
    public String uploadImage(MultipartFile file) {
        String rootPath = fileUploadConfig.getRootPath();
        String imageUrlPrefix = fileUploadConfig.getImageUrlPrefix();
        return FileUtil.writeSingleFileToDisk(file, rootPath, imageUrlPrefix);
    }

}
